﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CMP.ERP.Admin.ServiceReference1;

namespace CMP.ERP.Admin.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
        public ActionResult Login()
        {
            return View();
        }
        public ActionResult Denglu(string username, string userpass)
        {
            Userinfo u = new Userinfo();
            u.UserName = username;
            u.UserPass = userpass;
            if (client.Login(u) == 1)
            {
                Session["Username"] = username;
                Session["UserID"] = client.GetUserID(u);
                return Content("1");
            }
            else if (client.Login(u) == 0)
            {
                return Content("0");
            }
            else if (client.Login(u) == 2)
            {
                return Content("2");
            }
            else
            {
                return Content("<script>alert('登录失败');</script>");
            }
        }
        public ActionResult Zhuce(string username, string nickname, string password, string finalPWD)
        {
            if (username == "" || password == "" || finalPWD == "")
            {
                return Content("3");
            }
            else
            {
                if (password != finalPWD)
                {
                    return Content("0");
                }
                else
                {
                    Userinfo u = new Userinfo();
                    u.ParenCompanyName = nickname;
                    u.UserName = username;
                    u.UserPass = password;
                    if (client.Register(u) > 0)
                    {
                        Session["Username"] = username;
                        return Content("1");
                    }
                    else if (client.Register(u)==0)
                    {
                        return Content("4");
                    }
                    else
                    {
                        return Content("2");
                    }
                }
            }
        }
        public ActionResult Index()
        {
            return View();
        }
    }
}
